# @Time    :2025/3/27 20:36
### 编程题 2：嵌套字典数据处理
"""
有一个嵌套字典，存储了学生的课程成绩信息。 编写一个函数，计算每个学生的平均成绩，
并返回一个新的字典，键为学生名字，值为平均成绩。
结构如下：
students = {
    "Alice": {
        "Math": 85,
        "English": 90,
        "Science": 78
    },
    "Bob": {
        "Math": 92,
        "English": 88,
        "Science": 95
    },
    "Charlie": {
        "Math": 70,
        "English": 75,
        "Science": 80
    }
}
"""
students = {
    "Alice": {
        "Math": 85,
        "English": 90,
        "Science": 78
    },
    "Bob": {
        "Math": 92,
        "English": 88,
        "Science": 95
    },
    "Charlie": {
        "Math": 70,
        "English": 75,
        "Science": 80
    }
}


def stu_score(students):
    pj_score = {}
    for name, score in students.items():
        #       print(score)#取出的是三个字典里的k,v
        #       print(score.values())#取出的是三个字典里的v，就是三科分数
        pj_scores = sum(score.values()) / len(score)
        pj_score[name] = round(pj_scores, 2)
    return pj_score


print(stu_score(students))

